# -*- coding: utf-8 -*-

# __date:       2021/7/14
# __author:     Yang Chao
# __function:   Valid Parentheses 有效的括号

class Solution:

    def isValid(self, s: str) -> bool:
        # 使用栈的思想来解决
        stack = []
        for char in s:
            if char in "([{":
                stack.append(char)
            else:
                if not stack:
                    return False
                if char == ')' and stack[-1] != '(':
                    return False
                if char == ']' and stack[-1] != '[':
                    return False
                if char == '}' and stack[-1] != '{':
                    return False
                stack.pop()

        return stack == []